-----------------------------------------------------------------
--ECE 251 Switch - Single Frame Buffer block - by Peter Gebhard--
--- based on the Altera example 8x64 shift register with taps ---
-----------------------------------------------------------------

LIBRARY ieee;
USE ieee.std_logic_1164.all;

ENTITY frame_buffer IS
PORT (
	clk : 			IN STD_LOGIC;
	shift : 			IN STD_LOGIC;
	fb_in : 			IN STD_LOGIC_VECTOR(31 DOWNTO 0);
	fb_mac : 			OUT STD_LOGIC_VECTOR(95 DOWNTO 0);
	fb_ethertype : 		OUT STD_LOGIC_VECTOR(15 DOWNTO 0);
	fb_out : 			   OUT STD_LOGIC_VECTOR(31 DOWNTO 0)
);
END frame_buffer;

ARCHITECTURE Behavior OF frame_buffer IS

SUBTYPE fb_width IS STD_LOGIC_VECTOR(31 DOWNTO 0);
TYPE fb_length IS ARRAY (382 DOWNTO 0) OF fb_width;

SIGNAL fb : fb_length;

BEGIN
	PROCESS (clk)
	BEGIN
		IF (clk'EVENT and clk = '1') THEN
			IF (shift = '1') THEN 
				fb(382 DOWNTO 1) <= fb(381 DOWNTO 0);
				fb(0) <= fb_in;
			END IF;
		END IF;
	END PROCESS;

	fb_mac <= fb(380);
	fb_ethertype <= fb(377);
	fb_out <= fb(382);

END Behavior;
